<!-- 编辑弹窗 -->
<template>
  <div>
  <el-dialog
    title="添加补差明细"
    :visible="visible"
    width="1200px"
    :destroy-on-close="true"
    :lock-scroll="false"
    @update:visible="updateVisible">
    <el-form
      ref="form"
      :model="form"
      label-width="82px"
      @submit.native.prevent>
      <el-row :gutter="15" style="margin-bottom: 5px">
        <el-col :lg="9" :md="9">
          <el-form-item label="商品信息:" prop="invcode">
            <el-input
              clearable
              v-model="form.invcode"
              ref="txtInvcode"
              placeholder="输入商品编码或商品名称"/>
          </el-form-item>
        </el-col>
        <el-col :lg="7" :md="7">
          <el-form-item label="批号:" prop="vlotno">
            <el-input
              clearable
              v-model="form.vlotno"
              ref="txtVlotno"
              placeholder=""/>
          </el-form-item>
        </el-col>
        <el-col :lg="5" :md="5">
          <div class="ele-form-actions">
            <el-button
              type="primary"
              icon="el-icon-search"
              class="ele-btn-icon"
              size="small"
              @click="getSummaryList">查询
            </el-button>
            <el-button @click="reset" size="small">重置</el-button>
          </div>
        </el-col>
      </el-row>
    </el-form>
    <ele-pro-table
      ref="tableSummary"
      :datasource="dataSummary"
      :columns="columnsSummary"
      :toolbar="true"
      :need-page="false"
      :selection.sync="selectionSummary"
      highlight-current-row
      height="calc((100vh - 110px)/2)"
      max-height="calc((100vh - 110px)/2)"
      :loading="tableSummaryloading">      
    </ele-pro-table>
    <div slot="footer">
      <el-button @click="updateVisible(false)">关闭</el-button>
      <el-button
        type="primary"
        @click="save"
        :loading="loading">添加
      </el-button>
    </div>
  </el-dialog>
  </div>
</template>

<script>
import { mapGetters } from "vuex";
export default {
  name: 'SpbcSelectBCDetail',
  components:{},
  props: {
    // 弹窗是否打开
    visible: Boolean,
    // 修改回显的数据
    data: Object
  },
  computed: {
    ...mapGetters(["permission"]),
  },
  data() {
    return {
      // 表单数据
      form: {
        invcode:'',
        vlotno:''
      },
      dataSummary:[],
      selectionSummary:[],
      columnsSummary: [
        {
          columnKey: 'selection',
          type: 'selection',
          width: 45,
          align: 'center',
        },
        {
          columnKey: 'index',
          type: 'index',
          label: '序号',
          width: 45,
          align: 'center',
          fixed: "left"
        },     
        {
          prop: 'invcode',
          label: '商品编码',
          showOverflowTooltip: true,
          minWidth: 100,
          align: 'center'
        },
        {
          prop: 'invname',
          label: '商品名称',
          showOverflowTooltip: true,
          minWidth: 160,
          align: 'left'
        },
        {
          prop: 'gg',
          label: '规格',
          showOverflowTooltip: true,
          minWidth: 100,
          align: 'left'
        },
        {
          prop: 'materialunit',
          label: '单位',
          showOverflowTooltip: true,
          minWidth: 50,
          align: 'center'
        },
        {
          prop: 'manufacturer',
          label: '生产厂家',
          showOverflowTooltip: true,
          minWidth: 160,
          align: 'left'
        },
        {
          prop: 'vlotno',
          label: '批号',
          showOverflowTooltip: true,
          minWidth: 100,
          align: 'left'
        },
        {
          prop: 'dprodate',
          label: '生产日期',
          showOverflowTooltip: true,
          minWidth: 80,
          align: 'center'
        },
        {
          prop: 'vinvaliddate',
          label: '有效期',
          showOverflowTooltip: true,
          minWidth: 80,
          align: 'center'
        },
        {
          prop: 'nqtorigtaxprice',
          label: '含税单价',
          showOverflowTooltip: true,
          minWidth: 80,
          align: 'center'
        },
        {
          prop: 'nqtorigprice',
          label: '无税单价',
          showOverflowTooltip: true,
          minWidth: 80,
          align: 'center'
        },
        {
          prop: 'nastnum',
          label: '原销售数量',
          showOverflowTooltip: true,
          minWidth: 100,
          align: 'center'
        },
        {
          prop: 'remainnum',
          label: '可补差数量',
          showOverflowTooltip: true,
          minWidth: 100,
          align: 'center'
        },
        {
          prop: 'lastbilldate',
          label: '最后购货日期',
          showOverflowTooltip: true,
          minWidth: 100,
          align: 'center'
        },
        {
          prop: 'cgy',
          label: '采购员',
          showOverflowTooltip: true,
          minWidth: 80,
          align: 'center'
        }
       
      ],
      // 提交状态
      loading: false,
      // 是否是修改
      tableSummaryloading: false
    };
  },
  methods: {
    async getSummaryList(){
      this.tableSummaryloading = true;
      let param = {
        custcode:this.data.custcode,
        bcyjList:this.data.bcyjList,
        begindate:this.data.begindate,
        enddate:this.data.enddate,
        invcode:this.form.invcode,
        vlotno:this.form.vlotno,
        custaddrList:this.data.custAddr,
        gpoarea:this.data.gpoarea
      };
      var res = await this.$http.post('/spbc/summarylist', param);
      //console.log(res);
      if(res.status==200)
      {
        this.dataSummary = res.data.data;
        if(this.data.khlx == '医院'){
          for(let i=0; i<this.dataSummary.length;i++){
            this.dataSummary[i].nowsaleprice = this.dataSummary[i].nowsaleprice1;
          }
        }else if(this.data.khlx == '商业'){
          for(let i=0; i<this.dataSummary.length;i++){
            this.dataSummary[i].nowsaleprice = this.dataSummary[i].nowsaleprice2;
          }
        }
        this.tableSummaryloading = false;
      }
    },
    /* 添加 */
    save() {
      for(let i=0;i<this.selectionSummary.length;i++){
        this.selectionSummary[i].id= this.guid();
        this.$emit('done',this.selectionSummary[i]); 
      }    
    },
    /* 更新visible */
    updateVisible(value) {
      this.form.invcode='';
      this.form.vlotno='';
      this.dataSummary=[],
      this.selectionSummary=[],
      this.$emit('update:visible', value);
    },
    reset(){
      this.form.invcode='';
      this.form.vlotno='';
    },
    guid() {
      return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
          var r = Math.random() * 16 | 0,
              v = c == 'x' ? r : (r & 0x3 | 0x8);
          return v.toString(16);
      });
    }
    
  }  
}
</script>

<style scoped>
::v-deep .el-dialog__body {
  padding-top: 5px;
  padding-bottom: 5px;
}
.el-row {
  margin-bottom: -15px;
}
.el-row1 {
  margin-bottom: 5px;
  margin-top: 1px;
  display: flex;
  flex-wrap: wrap
}
</style>
